package com.auto.learning.view;



import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

import com.auto.learning.R;
import com.auto.learning.tools.CommonMethod;
import com.auto.learning.tools.Utils;

import android.R.string;
import android.app.Activity;
import android.content.Context;
import android.graphics.drawable.BitmapDrawable;
import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnTouchListener;
import android.view.ViewGroup.LayoutParams;
import android.widget.PopupWindow;
import android.widget.RelativeLayout;
import android.widget.TextView;

public class PupDingYueDialog {
	private PopupWindow popupWindow;
	private Context context;
	private TextView tv_message;
	private TextView tv_pay;
	private TextView tv_dimss;
	private PayUtil pay;

	public PupDingYueDialog(Context context){
		this.context=context;
		View view = LayoutInflater.from(context).inflate(R.layout.pup_dinggou, null);
		popupWindow = new PopupWindow(view, LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT, true);
		tv_message=(TextView) view.findViewById(R.id.tv_message);
		tv_pay=(TextView) view.findViewById(R.id.tv_pay);
		tv_dimss=(TextView) view.findViewById(R.id.tv_dimss);
		tv_dimss.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				popupWindow.dismiss();
			}
		});
		// 创建日期对象 当前时间
		Date date = new Date();
		// 给定模式
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		String s = sdf.format(date);
		//对于时间运算
		Calendar now = Calendar.getInstance();
		now.setTime(date);
		now.add(Calendar.YEAR,1);//年数加1
//		now.add(Calendar.DAY_OF_YEAR,-1);//天数减1
		Date dt1=now.getTime();
        String reStr = sdf.format(dt1);
		setMessageText(s, reStr);
		tv_pay.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				if(pay!=null){
					pay.setpay();
				}
				dissmiss();
			}
		});
		popupWindow.setFocusable(true);
		popupWindow.setOutsideTouchable(true);
		popupWindow.setBackgroundDrawable(new BitmapDrawable());
	
	}
	public interface PayUtil{
		public void setpay();
	}
	public void dissmiss(){
		popupWindow.dismiss();
	}
	public void setMessageText(String ksdate,String jsdate){
		tv_message.setText("");
		String str = "您将订阅"+ksdate+"至"+jsdate+"的内容\n订阅后不支持退订、转让，请再次确定";
		tv_message.setText(str);
	}
	public void setPayOnClick(PayUtil payUtil){
		this.pay=payUtil;
	}
	public void show(View dropview){
		popupWindow.showAtLocation(dropview, Gravity.BOTTOM, 0, 0);
	}
}
